Skip to content

tests: load JSON fixtures at runtime for crates.io archives - #444

Open
rome-xi wants to merge 1 commit into
servo:mainfrom
rome-xi:contrib/rust-cssparser-213
Open

rome-xi wants to merge 1 commit into
servo:mainfrom
rome-xi:contrib/rust-cssparser-213

Conversation

@rome-xi

@rome-xi rome-xi commented Aug 24, 2026

Copy link
Copy Markdown

Closes #213.

Replace include_str! for the CSS parsing JSON fixtures with std::fs::read_to_string so cargo test compiles from the crates.io package (those files are in exclude). Missing fixtures still fail at runtime (no silent green); they can be --skipped when packaging.

@emilio

emilio commented Aug 24, 2026

Copy link
Copy Markdown
Member

Please run cargo fmt so CI is happy, looks good with that :)

@emilio emilio left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Ticking request changes so I notice when it gets updated)

@rome-xi
rome-xi force-pushed the contrib/rust-cssparser-213 branch from c811ec6 to 07c058c Compare August 27, 2026 07:57

@emilio emilio left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I don't think ignoring them in miri is good... can we keep the include_str! in miri instead?

@rome-xi

rome-xi commented Aug 31, 2026

Copy link
Copy Markdown
Author

Hmm, I don't think ignoring them in miri is good... can we keep the include_str! in miri instead?

Thanks — updated so miri still uses include_str! for the JSON fixtures, while non-miri keeps runtime load for crates.io archives. Dropped the miri ignores on those tests.

Comment thread src/tests.rs Outdated
"stylesheet_bytes.json" => include_str!("css-parsing-tests/stylesheet_bytes.json"),
"An+B.json" => include_str!("css-parsing-tests/An+B.json"),
"urange.json" => include_str!("css-parsing-tests/urange.json"),
other => panic!("unknown css-parsing-tests fixture: {other}"),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems unfortunate, let's just make it a macro like:

macro_rules! css_parsing_test_json {
  ($path:tt) {
    #[cfg(miri)]
    String::from(include_str!($path))
    #[cfg(not(miri))]
    std::fs::read_to_string(&format!("{}/src/{}", env!(..), $path)).unwrap()
  }
}

Seems like that should work?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done — replaced the match helper with css_parsing_test_json! as suggested (miri: include_str!, otherwise fs::read_to_string via CARGO_MANIFEST_DIR). Pushed in 28f5c96.

@emilio

emilio commented Sep 20, 2026

Copy link
Copy Markdown
Member

@rome-xi could you squash your commits into one?

Use css_parsing_test_json! so miri keeps include_str! while normal
builds load fixtures from disk via CARGO_MANIFEST_DIR (crates.io
archives omit include_str!-embedded paths).
@rome-xi
rome-xi force-pushed the contrib/rust-cssparser-213 branch from 28f5c96 to 5b063db Compare September 21, 2026 01:41
@rome-xi

rome-xi commented Sep 21, 2026

Copy link
Copy Markdown
Author

Squashed into a single commit (5b063db) as requested — history on contrib/rust-cssparser-213 is now one commit on top of current main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cargo test fails on archive from crates.io

2 participants